package com.mudingkou.mos.config;

import com.mudingkou.mos.common.exception.BusinessException;
import com.mudingkou.mos.common.pojo.response.BaseResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {
 
    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public BaseResponse bizExceptionHandler(HttpServletRequest req, BusinessException e){
        return BaseResponse.fail(e.getCode(),e.getMessage());
    }
 
    @ExceptionHandler(value =Exception.class)
    @ResponseBody
    public BaseResponse exceptionHandler(HttpServletRequest req, Exception e){
        return BaseResponse.fail(e.getMessage());
    }
}